﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Company.Core.Helpers
{
    /// <summary>
    /// 内存帮助
    /// </summary>
    public static class MemoryHelper
    {
        /// <summary>
        /// 内存清零
        /// </summary>
        /// <param name="intPtr"></param>
        /// <param name="size"></param>
        [DllImport("kernel32.dll", EntryPoint = "RtlZeroMemory")]
        public static extern void ZeroMemory(IntPtr intPtr, long size);

        /// <summary>
        /// 内存复制
        /// </summary>
        /// <param name="dest">目标句柄</param>
        /// <param name="src">当前句柄</param>
        /// <param name="size">字节数</param>
        [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", CharSet = CharSet.Ansi)]
        public static extern void CopyMemory(IntPtr dest, IntPtr src, long size);

        /// <summary>
        /// 将指定的值写入内存
        /// </summary>
        /// <param name="dest">目标句柄</param>
        /// <param name="size">字节数</param>
        /// <param name="value">填充的字节值</param>
        [DllImport("kernel32.dll", EntryPoint = "RtlFillMemory", CharSet = CharSet.Ansi)]
        public static extern void FillMemory(IntPtr dest, long size, byte value);
    }
}
